package org.smartercontext.contextmger.fixedgatherers;

import org.smartercontext.contextmger.contextsphere.ContextManagerController;
import org.smartercontext.contextmger.converters.RDFConverter;
import org.smartercontext.contextmger.locationgatherer.*;

import com.hp.hpl.jena.rdf.model.Model;

/**
 * 
 * @author JuanPablo
 * @version 1.0
 * @creation_date 09 Mar 2014
 * This class receive the user's current location
 *
 */
public class LocationGatherer implements ILocationGatherer {

	public LocationGatherer(){
		
	}
	
	@Override
	public void receiveCurrentLocation(String latitude, String longitude, String user){
		
		
		System.out.println(latitude+"-"+longitude+"-"+user);
		
		IGeoSearcher geoSearcher=new GeoSearcher();
		CompleteGeolocation received =geoSearcher.receiveCurrentLocation
				(latitude, longitude);
		
		
		/*
		 * Usando el user y el objeto received, crear el RDF/XML para almacenarlo
		 */
		
		if(received!=null){
			System.out.println("user: "+user+" Geo: \n"+received.getComplete_address());
			received.setUser(user);
			
			RDFConverter rdfconv = new RDFConverter();
			ContextManagerController.contextManagerController();
			Model usermodel;
			try {
				usermodel = ContextManagerController.getUsermodel(user);
				Model usermodelU = rdfconv.writeLocation(usermodel, received);
				ContextManagerController.integrateContext(usermodelU, user);
				
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			
			
		}
		
		
	}
}
